package com.pavelk.orion.model
{
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.net.URLLoader;
	import flash.net.URLRequest;	
		
    import org.puremvc.as3.interfaces.IProxy;
    import org.puremvc.as3.patterns.proxy.Proxy;
    import org.puremvc.as3.utilities.loadup.interfaces.ILoadupProxy;
    
    import com.pavelk.orion.ApplicationFacade;
    
    //import com.pavelk.orion.model.vo.*;
	
	public class SiteDataProxy extends EntityProxy implements ILoadupProxy
	{
		public static const NAME  :String = "SiteDataProxy";
        public static const SRNAME:String = "SiteDataSRProxy";
		
		public function SiteDataProxy()
		{
			super( NAME, new Object() );
		}
		
		public function load() : void
		{
			sendNotification( ApplicationConstants.SITE_DATA_LOADING );
			
			var request:URLRequest = new URLRequest("data/data.xml");
			var loader:URLLoader = new URLLoader();
			
			loader.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
            loader.addEventListener(Event.COMPLETE, loaderCompleteHandler);
			
			loader.load(request);
		}
		
		private function loaderCompleteHandler( e:Event ):void 
		{			
			var xml:XML = new XML( e.target.data );
			
			sendLoadedNotification( ApplicationConstants.SITE_DATA_LOADED, NAME, SRNAME );
		}
		
		private function errorHandler(e:IOErrorEvent):void 
		{
            sendLoadedNotification( ApplicationConstants.SITE_DATA_FAILED, NAME, SRNAME );
        }

	}
}